#include<bits/stdc++.h>
#define int __int128
using namespace std;
namespace IO{
	char Is[(1<<21)+10],Os[(1<<21)+10];
	int Ipt,Opt;
	char gc(){
		if(Ipt==1<<21)Ipt=0;
		if(!Ipt){Is[fread(Is,1,1<<21,stdin)]=0;}
		return Is[Ipt++];
	}
	void flush(){fwrite(Os,1,Opt,stdout);Opt=0;}
	void pc(char x){
		if(Opt==1<<21)flush();
		Os[Opt++]=x;
	}
	inline int read(){
		int x=0;bool f=0;char ch=gc();
		while(ch<'0'||ch>'9')f^=(ch=='-'),ch=gc();
		while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=gc();
		return f?-x:x;
	}int pstk[40];
	inline void write(int x){
		if(!x)return void(pc('0'));
		if(x<0)pc('-'),x=-x;
		int len=0;
		for(;x;x/=10)pstk[++len]=x%10;
		while(len)pc(pstk[len--]+'0');
	}
}
using namespace IO;
const int Maxn=2e6+5;
int n,k,a[Maxn],b[Maxn],p[Maxn];
int f[2505][2505];
namespace sub1{
	inline void solve(){
		n=read();k=read();int V=0;
		for(int i=1;i<n;i++)a[i]=read(),V=max(V,a[i]);
		for(int i=1;i<=k;i++)b[i]=read()+b[i-1];
		for(int i=1;i<k;i++)p[i]=b[i];
		for(int i=k;i<=n-k+1;i++)p[i]=b[k];
		for(int i=1;i<k;i++)p[n-k+1+i]=b[k]-b[i];
		for(int i=0;i<=V;i++)f[1][i]=0;
		for(int i=0;i<=a[1];i++)f[1][i]=p[1]*i;
		int ans=0;
	//	for(int i=1;i<=n;i++)printf("p[%d]=%d\n",i,p[i]);
		for(int i=2;i<=n;i++){
			for(int j=1;j<=V;j++)f[i][j]=0;
			for(int j=0;j<=a[i-1];j++){
				f[i][j]=f[i-1][a[i-1]-j]+j*p[i];
				if(i==n)ans=max(ans,f[i][j]);
	//			printf("f[%d][%d]=%d\n",i,j,f[i][j]);
			}for(int j=1;j<=V;j++)f[i][j]=max(f[i][j],f[i][j-1]);
		}write(ans);pc('\n');flush();
//		printf("%lld\n",ans);
//		cerr<<(f[n][0]==ans||f[n][a[n-1]]==ans)<<'\n';
	}
}
signed main(){
	freopen("festival.in","r",stdin);
	freopen("festival.out","w",stdout);
	int opp=read(),T=read();
	if(opp<=6){
		while(T--)sub1::solve();
		return 0;
	}
	return 0;
}
/*
0 2
4 2
5 4 2
2 1
7 4
4 8 6 7 8 3
3 5 1 2

0 1
7 4
4 8 6 7 8 3
3 5 1 2

0 1
60 10
12 13 10 2 10 5 5 1 2 8 13 9 10 4 4 9 9 9 7 6 5 2 13 1 9 3 11 1 5 13 13 13 2 7 3 6 10 12 9 13 4 3 12 7 1 1 3 1 10 8 2 11 1 3 3 10 7 9 4 
55 32 70 67 75 15 95 9 18 89 
*/
